from ConfigParser import SafeConfigParser
from os import sep , listdir, getenv
from os.path import exists, realpath, isdir, isfile
from webbrowser import open_new_tab

def available_search_engines():
    toreturn = []
    if exists(tsearchfolder) and isdir(tsearchfolder):
        for j in listdir(tsearchfolder):
            j = tsearchfolder + sep + j
            if isfile(j):
                f = open(j,"r")
                for z in f.readlines():
                    i = z.split(",")
                    if len(i)==4:
                        toreturn.append(
                          [i[0].strip(),
                           i[1].strip(),
                           i[2].strip(),
                           bool(i[3])])
                f.close()
    return toreturn

def open_browser(text):
    open_new_tab(text)
    #system("firefox --new-tab %s" % row[1].replace("%s",text))

def set_tsearchfolder(new):
    global tsearchfolder
    tsearchfolder = new

def get_tsearchfolder():
    return tsearchfolder

tsearchfolder = "tsengines"
